package com.woniuxy.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.woniuxy.dao.RepairRecordMapper;
import com.woniuxy.pojo.RepairRecord;
import com.woniuxy.service.RepairRecordService;
import com.woniuxy.util.DataGridView;
import com.woniuxy.vo.RepairRecordVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class RepairRecordImpl implements RepairRecordService{
    @Autowired
    private RepairRecordMapper repairRecordMapper;
    @Override
    public DataGridView selectRepairRecordsByProperty(RepairRecordVo repairRecordVo) {
        Page<Object> page = PageHelper.startPage(repairRecordVo.getPage(),repairRecordVo.getLimit());
        List<RepairRecord> repairRecords = this.repairRecordMapper.selectRepairRecordsByProperty(repairRecordVo);
        return new DataGridView(page.getTotal(),repairRecords);
    }
    @Transactional
    @Override
    public void deleteRepairRecordById(int id) {
        repairRecordMapper.deleteRepairRecordById(id);
    }
    @Transactional
    @Override
    public void removeRepairRecord(Integer[] ids) {
        if (ids!=null&&ids.length>0){
            for (Integer id:ids){
                this.deleteRepairRecordById(id);
            }
        }
    }
    @Transactional
    @Override
    public boolean insertRepairRecord(RepairRecord repairRecord) {
        boolean flag=false;
        int i = this.repairRecordMapper.insertRepairRecord(repairRecord);
        if(i>0){
            flag=true;
        }
        return flag;
    }
    @Transactional
    @Override
    public boolean updataRepairRecord(RepairRecord repairRecord) {
        boolean flag=false;
        int i = this.repairRecordMapper.updataRepairRecord(repairRecord);
        if (i>0){
            flag=true;
        }
        return flag;
    }
}
